#include "mypushbutton.h"
#include "ui_mypushbutton.h"
#include <QDebug>
#include <QMutex>
#include "chatting_room.h"

extern std::map<std::string, std::vector<std::string> > global_ip2msg;
extern QMutex global_ip2msg_mutex;
MyPushButton::MyPushButton(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::MyPushButton)
{
    ui->setupUi(this);
    QB = new QPushButton;
    //QObject::connect(this,SIGNAL(sendIP(QString)),this,SLOT(showHis(QString)));
 }

MyPushButton::~MyPushButton()
{
    delete ui;
}

void MyPushButton::on_clicked() {
    QString temp_ip = QB->text();
    /*
    global_ip2msg_mutex.lock();
    std::vector<std::string> msg_vec = global_ip2msg[temp_ip.toStdString()];
    global_ip2msg.erase(temp_ip.toStdString());
    global_ip2msg_mutex.unlock();
    std::string tmp_info;

    for (auto iter = msg_vec.begin(); iter != msg_vec.end(); ++iter) {
        tmp_info += temp_ip.toStdString() + ":";
        tmp_info += (*iter);
        tmp_info += "\n";
    }

    std::cout << tmp_info << std::endl;
    //info = temp_ip + "#" + QString::fromStdString(tmp_info);
    */
    info = temp_ip;

    //qDebug() << info;
//    emit sendIP(st);
//    QObject::disconnect(this,SIGNAL(sendIP(QString)),ch,SLOT(showHis(QString)));
}
